package com.vim.modules.mall.service.impl;

import com.github.pagehelper.PageInfo;
import com.vim.common.utils.AssertUtils;
import com.vim.common.utils.JsonUtils;
import com.vim.modules.mall.model.base.CommonPage;
import com.vim.modules.mall.model.base.MallResponseEntity;
import com.vim.modules.mall.model.base.Page;
import com.vim.modules.mall.model.base.PageConvertUtils;
import com.vim.modules.mall.model.mallGoods.MallGoods;
import com.vim.modules.mall.model.mallOrder.MallOrder;
import com.vim.modules.mall.model.mallSys.MallSysTask;
import com.vim.modules.mall.service.MallSysTaskService;
import com.vim.modules.mall.service.remote.RemoteMallSysTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @作者 Administrator
 * @时间 2020-10-06 11:20
 * @版本 1.0
 */
@Service
public class MallSysTaskServiceImpl implements MallSysTaskService {

    @Autowired
    private RemoteMallSysTaskService remoteMallSysTaskService;

    /**
     * 任务列表数据
     */
    @Override
    public PageInfo<MallSysTask> taskList(Page page) {
        MallResponseEntity<CommonPage<MallSysTask>> result = remoteMallSysTaskService.taskList(page.getPageNo(), page.getPageSize());
        AssertUtils.assertAjaxOK(result);
        return PageConvertUtils.convert(result.getData());
    }

    /**
     * 修改任务状态
     * @param taskId 任务id
     * @param status 状态（0停止 1启用）
     */
    @Override
    public void sysTaskCtrl(Long taskId, String status) {
        MallResponseEntity result = remoteMallSysTaskService.taskCtrl(taskId, status);
        AssertUtils.assertAjaxOK(result);
    }

    /**
     * 任务信息
     * @param taskId
     */
    @Override
    public MallSysTask taskInfo(Long taskId) {
        MallResponseEntity<MallSysTask> result = remoteMallSysTaskService.taskInfo(taskId);
        AssertUtils.assertAjaxOK(result);
        return result.getData();
    }

    /**
     * 任务保存
     */
    @Override
    public MallSysTask sysTaskSave(MallSysTask task) {
        MallResponseEntity<MallSysTask> result = remoteMallSysTaskService.taskSave(JsonUtils.toString(task));
        AssertUtils.assertAjaxOK(result);
        return result.getData();
    }
}
